package org.gis.mapserver.plugins.rasterimage;

import org.objective.base.BaseField;
import org.objective.base.BaseObject;
import org.objective.base.BaseType;
import org.objective.base.BaseView;
import org.objective.base.Construction;
import org.objective.base.LazyFieldCollection;
import org.objective.base.ObjectCollection;
import org.objective.base.Storage;

/**
 *
 * @author gus
 */
public class RasterImageObject extends BaseObject
{
    public RasterImageObject(Storage storage, long id, BaseType type, BaseObject owner) throws Exception
    {
        super(storage, id, type, owner);
        setObjectName("RasterImage");
    }

    @Override
    protected void createDefaultContent() throws Exception
    {
        RasterField field = (RasterField) getFields().newInstance(new Constructor(this, storage));
        field.setFieldName("testField");
        field.setDescription("My first field");
    }

    @Override
    protected ObjectCollection<BaseView, BaseObject> createViewCollection()
    {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    protected ObjectCollection<BaseField, BaseObject> createFieldCollection()
    {
        return new LazyFieldCollection<BaseField, BaseObject>(this, new Constructor(this, storage));
    }

    @Override
    public String getName()
    {
        return "RasterImageObject";
    }
}

class Constructor implements Construction<BaseField>
{
    private BaseObject owner;
    private Storage storage;

    public Constructor(BaseObject owner, Storage storage)
    {
        this.owner = owner;
        this.storage = storage;
    }

    @Override
    public BaseField constructObject(long oid)
    {
        return new RasterField(storage, oid, owner);
    }

    @Override
    public Class getTypeCreation()
    {
        return RasterField.class;
    }
}
